export const setLocalStroage = (key, value, time) => {
  const obj = {};
  obj[key] = value;
  if (time) {
    obj.overTime = time * 1000 * 60 * 60 * 24 + Date.now();
  }
  window.localStorage.setItem(key, JSON.stringify(obj));
};

export const getLocalStroage = (key) => {
  const value = JSON.parse(window.localStorage.getItem(key));
  if (value) {
    if (value.overTime != null) {
      if (Date.now() >= value.overTime) {
        window.localStorage.removeItem(key);
        return false;
      } else {
        return value[key];
      }
    } else {
      return value[key];
    }
  }
};

export const clearLocalStroage = () => {
  return window.localStorage.clear();
};

export const removeLocalStroage = (key) => {
  return window.localStorage.removeItem(key);
};
